package cn.pku.sirx.snad.ass.service.impl;

import java.util.LinkedList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.pku.sirx.snad.ad.model.UserContext;
import cn.pku.sirx.snad.ad.model.entity.AdContent;
import cn.pku.sirx.snad.ad.service.IAdSelectionService;
import cn.pku.sirx.snad.ass.strategy.IAdReorderStrategy;
import cn.pku.sirx.snad.ass.strategy.IAdRetrievalStrategy;

/**
 * @author WangXiao
 */
public class AdSelectionServiceImpl implements IAdSelectionService {

	@Override
	public List<AdContent> getAds(int count, UserContext userContext) {
		LOG.info("Begin ad selection:" + userContext);
		List<AdContent> candidateAds = adRetrievalStrategy
				.retrieveAds(userContext);
		List<AdContent> result = adReorderStrategy.reorderAds(candidateAds,
				userContext);
		LOG.info("End ad selection");

		result = new LinkedList<AdContent>();
		result.add(new AdContent("123", "wewwr", "vsdfddg", "http://www.baidu.com",
				"www.youdao.com"));
		result.add(new AdContent("1234", "wewwr", "vsdfddg", "http://www.baidu.com",
		"www.youdao.com"));
		return result;
	}

	private IAdRetrievalStrategy adRetrievalStrategy;
	private IAdReorderStrategy adReorderStrategy;

	public void setAdRetrievalStrategy(IAdRetrievalStrategy adRetrievalStrategy) {
		this.adRetrievalStrategy = adRetrievalStrategy;
	}

	public void setAdReorderStrategy(IAdReorderStrategy adReorderStrategy) {
		this.adReorderStrategy = adReorderStrategy;
	}

	private static final Log LOG = LogFactory
			.getLog(AdSelectionServiceImpl.class);

}
